﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameworkManapro.BusinessModel;
using FrameworkManapro.Utilities;
using FrameworkManapro.WebUI;

namespace GMAC.ReportingSystem.Business.Components
{
    public class InsuranceCompanyComponent : IBusinessComponent<Entities.InsuranceCompany>
    {
        private DataAccess.InsuranceCompanyDataAccess dac;

        #region Constructors

        public InsuranceCompanyComponent()
        {
            dac = new DataAccess.InsuranceCompanyDataAccess();
        }

        #endregion

        ////////////////////////////////////////////////////////////////////

        #region IBusinessComponent<InsuranceCompany> Members

        public int Create(Entities.InsuranceCompany entityToCreate)
        {
            if (Validate(entityToCreate))
            {
                var result = dac.Insert(entityToCreate);
                return result;
            }
            return 0;
        }

        //------------------------------------------------------

        public int Delete(Entities.InsuranceCompany entityToDelete)
        {
            if (entityToDelete.Id <= 0)
            {
               throw new ArgumentOutOfRangeException("InsuranceCompanyId", "Value must be greater than zero.");
            }

            return dac.Delete(entityToDelete);
        }

        //------------------------------------------------------

        public int Edit(Entities.InsuranceCompany entityToEdit)
        {
            if (entityToEdit.Id <= 0)
            {
                throw new ArgumentOutOfRangeException("InsuranceCompanyID", "Value must be greater than zero.");
            }

            return Validate(entityToEdit) ? dac.Update(entityToEdit) : 0;
        }

        //------------------------------------------------------

        public Entities.InsuranceCompany GetDetails(object entityId)
        {
            return dac.Get(entityId);
        }

        //------------------------------------------------------

        protected bool Validate(Entities.InsuranceCompany InsuranceCompany)
        {
            if (InsuranceCompany == null)
            {
                throw new ArgumentNullException("InsuranceCompany", "The argument cannot be null.");
            }
            if (string.IsNullOrEmpty(InsuranceCompany.Id.ToString()))
            {
                throw new ArgumentNullException("Id", "The argument cannot be null.");
            }
            if (string.IsNullOrEmpty(InsuranceCompany.Status.ToString()))
            {
                throw new ArgumentNullException("Status", "The argument cannot be null.");
            }
            if (string.IsNullOrEmpty(InsuranceCompany.Name))
            { 
                throw new ArgumentNullException("Name", "The argument canno be null."); 
            }

            return true;
        }

        //------------------------------------------------------

        #endregion

        ////////////////////////////////////////////////////////////////////

        #region Public Methods

        public Entities.InsuranceCompanyCollection GetList()
        {
            return dac.GetList();
        }

        //------------------------------------------------------

        public Entities.InsuranceCompanyCollection Search(int? id, string name, PagingDetails paging)
        {
            if (name == null)
            {
                name = string.Empty;
            }

            return dac.Search(id, name, paging);
        }

        #endregion
    }
}
